

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

public class DrawUtil {
	public static void drawRect(Graphics g, int posX, int posY, int width,
			int height, Color color) {
		g.setColor(color);
		g.drawRect(posX, posY, width, height);
	}

	public static void fillRect(Graphics g, int posX, int posY, int width,
			int height, Color color) {
		g.setColor(color);
		g.fillRect(posX, posY, width, height);
	}

	public static void fillRoundRect(Graphics g, int posX, int posY, int width,
			int height, int arcWidth, int arcHeight, Color color) {
		g.setColor(color);
		g.fillRoundRect(posX, posY, width, height, arcWidth, arcHeight);
	}

	public static void drawImageRotate(Graphics g, Image img, int posX,
			int posY, int width, int height, Double rotate) {
		if (img != null) {
			Graphics2D g2 = (Graphics2D) g;
			g2.rotate(Math.toRadians(rotate), (width >> 1) + posX,
					(height >> 1) + posY);
			g2.drawImage(img, posX, posY, width, height, null);
		}
	}

	public static void drawImage(Graphics g, Image img, int posX, int posY,
			int width, int height) {
		if (img != null) {
			g.drawImage(img, posX, posY, width, height, null);
		}
	}

	public static void drawImage(Graphics g, String imPath, int posX, int posY,
			int width, int height) {
		drawImage(g, getImage(imPath), posX, posY, width, height);
	}

	public static BufferedImage getImage(String imPath) {
		if (imPath == null)
			return null;
		File imFile = new File(imPath);
		BufferedImage bi = null;
		if (imFile != null && imFile.exists() && imFile.isFile()) {
			try {
				bi = ImageIO.read(imFile);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return bi;
	}
	/**
	 * ------------------------------------------------------------------------
	 * -------
	 */

}
